package com.yuyou.fn.tms.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * Created by wens on 16-11-30.
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Value("${dev.env}")
    private boolean dev;

    @Bean
    public Docket tmsApi() {
        return new Docket(DocumentationType.SWAGGER_2).groupName("tms网报接口").forCodeGeneration(true).select().apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.regex("/api/data.*"))
                .build().apiInfo(apiInfo()).enable(dev);
    }

    @Bean
    public Docket resourceApi() {
        return new Docket(DocumentationType.SWAGGER_2).groupName("潜客资源接口").forCodeGeneration(true).select().apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.regex("/api/resource.*"))
                .build().apiInfo(apiInfo()).enable(dev);
    }

    private ApiInfo apiInfo() {
        Contact contact=new Contact("wens","www.google.com","wenzuojing@gmail.com");
        ApiInfo apiInfo = new ApiInfoBuilder().title("誉优").description("誉优后台接口").contact(contact).version("1.0").build();
        return apiInfo;
    }
}
